$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update(id) {
 var check = document.getElementsByTagName('input')[5];
    if(check.checked == true){
        $('#delFlag').val('1');
    }
    else{
        $('#delFlag').val('0');
    }
    var data = $('#signupForm').serialize();
	$.ajax({
		cache : true,
		type : "POST",
		headers:PRIVATE_HEADERS,
		url : API_SERVER_URL + "system/sysDept/update",
		data : data,// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				window.parent.location.reload() ;
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
        			name : {
        				required : true
        			},
        			orderNum : {
                        required : true,
                        digits : true
                    }
        		},
        		messages : {
        			name : {
        				required : icon + "请输入部门名称"
        			},
        			orderNum : {
        			    required : icon + "请输入排序号",
        			    digits:icon + "请输入整数数字",
        			}
        		}
	})
}
var openDept = function(){
	layer.open({
		type:2,
		title:"选择部门",
		area : [ '300px', '450px' ],
		content:"../../../templates/system/dept/deptTree.html"
	})
}